package homework14;

public class Work3_Runnable implements Runnable {
    private  int n = 100;

    @Override
    public void run() {
        while(true) {
            synchronized(Work3_Runnable.class) {
                if (n <= 0) {
                    System.out.println("票已售罄！");
                    break;
                } else {
                    System.out.println(Thread.currentThread().getName() + " 卖掉第" + (101 - n) + "张票，剩余" + (n - 1) + "张票！");
                    n--;
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
